/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Plano;

import Geral.ErroInternoException;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Ivaldo
 */
@Stateless
public class CadastroPlano {
    
    @EJB
    private IRepositorioPlano repPlano;
    
    public CadastroPlano(){
        
    }
    
    public void adicionar(Plano plano) throws ErroInternoException, PlanoExistenteException{
        try{
            Plano plano2 = this.repPlano.buscarPlano(plano.getId());
            if(plano2 != null){
                throw new PlanoExistenteException();
            }
        }catch(PlanoInexistenteException e){
            this.repPlano.adicionar(plano);
        }
    }
    
    public Plano buscarPlano(long id_plano) throws ErroInternoException, PlanoInexistenteException{
        try{
            return this.repPlano.buscarPlano(id_plano);
        }catch(ErroInternoException e){
            throw new ErroInternoException(e);
        }
    }
    
    public void atualizar(Plano plano) throws ErroInternoException, PlanoInexistenteException{
        this.repPlano.atualizar(plano);
    }
    
    public void remover(long id_plano) throws ErroInternoException, PlanoInexistenteException{
        this.repPlano.remover(id_plano);
    }
    
    public List<Plano> listaPlano(Plano plano) throws ErroInternoException{
        return this.repPlano.listaPlano(plano);
    }
}
